package com.pearl.boot;

import lombok.NoArgsConstructor;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * 自定义启动类
 *
 * @author TangDan
 * @version 1.0
 * @since 2022/9/5
 */
@NoArgsConstructor
public class PearlSpringApplication {

    /**
     * Run 方法
     *
     * @param appName 应用名称
     * @param source  主类
     * @param args    启动参数
     */
    public static ConfigurableApplicationContext run(String appName, Class source, String... args) {
        SpringApplicationBuilder builder = createSpringApplicationBuilder(appName, source, args);
        PearlBanner pearlBanner = new PearlBanner();
        pearlBanner.setAppName(appName);
        builder.banner(pearlBanner);
        return builder.run(args);
    }

    /**
     * 获取SpringApplication构建者
     */
    public static SpringApplicationBuilder createSpringApplicationBuilder(String appName, Class source, String... args) {
        return new SpringApplicationBuilder(source);
    }
}
